package com.wiz.weixin.task;

import javax.annotation.Resource;

import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.wiz.weixin.common.GlobalConstant;
import com.wiz.weixin.common.TencentConstant;
import com.wiz.weixin.manager.TencentManager;
import com.wiz.weixin.util.JSSDKUtil;

@Component
public class TecentWxTokenTask implements TencentConstant{
	private transient final Logger log = LoggerFactory.getLogger(getClass());
	
	@Resource
	private TencentManager tencentManager;
	
	/**
     * 定时更新微信使用token，间隔1小时55分
     */
    @Scheduled(fixedRate=6900000)
    public void updateWxToken() {
    	try {
			tencentManager.resetWxToken();
			JSSDKUtil.getJsApiTicket(GlobalConstant.tencent_wx_token);
			log.info("reset WxToken success on time");
		} catch (JSONException e) {
			log.error("reset WxToken fail,we must reset in 5 minutes");
		}
    }
}
